package com.example.mybatisplus.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.mybatisplus.mapper.RepairMapper;
import com.example.mybatisplus.model.domain.Dot;
import com.example.mybatisplus.model.domain.Keeper;
import com.example.mybatisplus.mapper.KeeperMapper;
import com.example.mybatisplus.model.domain.Leader;
import com.example.mybatisplus.model.domain.Repair;
import com.example.mybatisplus.model.dto.RepairForm;
import com.example.mybatisplus.service.KeeperService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zzy
 * @since 2024-06-24
 */
@Service
public class KeeperServiceImpl extends ServiceImpl<KeeperMapper, Keeper> implements KeeperService {
    @Autowired
    private  KeeperMapper keeperMapper;
    @Autowired
    private RepairMapper repairMapper;

    @Override
    public List<Keeper> selectKeeperByNameAndAccount(Dot dot) {

        QueryWrapper<Keeper> wrapper = new QueryWrapper<Keeper>()
                .like("name", dot.getData().get("keeperName"))
                .like("account", dot.getData().get("keeperAccount"));
        Page<Keeper> keeperPage = new Page<>(dot.getPageNo(), dot.getPageSize());
        IPage<Keeper> keeperIPage = this.baseMapper.selectPage(keeperPage, wrapper);
        return keeperIPage.getRecords();
    }
    public List<RepairForm> getUndoRepair(Dot dot){
        return keeperMapper.getUndoRepair(dot);
    }
    public List<RepairForm> getDoneRepair(Dot dot){
        return keeperMapper.getDoneRepair(dot);
    }
    public boolean updateRepairKeeper(Long repairID){
        UpdateWrapper<Repair> wrapper = new UpdateWrapper<>();
        wrapper.eq("id",repairID);
        wrapper.set("state","已完成");
        return repairMapper.update(null,wrapper)>0;
    }
    public  List<RepairForm> getRepairByTypeKeeper(Dot dot){
        return keeperMapper.getRepairByTypeKeeper(dot);
    }
}
